package com.bianmaba.remote;

import com.bianmaba.commons.bean.result.OperationResult;
import com.bianmaba.configuration.MetricPropertiesConfiguration;
import com.bianmaba.remote.supports.MetricRemoteRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.Map;

@Service
public class MemberService {
    @Autowired
    private MetricRemoteRequestService remoteRequestService;
    @Autowired
    private MetricPropertiesConfiguration.MetricProperties metricProperties;

    public OperationResult listByNo(String no) {
        String url = metricProperties.getMicroService().getMemberListByProjectNo();

        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        HttpHeaders headers = new HttpHeaders();

        headers.add("client-id", metricProperties.getMicroService().getClientId());
        headers.add("client-secret", metricProperties.getMicroService().getClientSecret());

        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        map.add("projectNo", no);
        HttpEntity<Map> entity = new HttpEntity(map, headers);
        OperationResult result = remoteRequestService.postForList(url, entity);
        return result;
    }
}
